package com.xiaoke;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class MovieInfo implements WritableComparable<MovieInfo> {
	private String title;
	private int year;
	private String type;
	private float star;
	private String director;
	private String actor;
	private String time;
	private String film_page;

	public void write(DataOutput out) throws IOException {
		out.writeUTF(this.title);
		out.writeInt(this.year);
		out.writeUTF(this.type);
		out.writeFloat(this.star);
		out.writeUTF(this.director);
		out.writeUTF(this.actor);
		out.writeUTF(this.time);
		out.writeUTF(this.film_page);

	}

	public void readFields(DataInput in) throws IOException {
		// TODO 自动生成的方法存根
		this.title = in.readUTF();
		this.year = in.readInt();
		this.type = in.readUTF();
		this.star = in.readFloat();
		this.director = in.readUTF();
		this.actor = in.readUTF();
		this.time = in.readUTF();
		this.film_page = in.readUTF();
	}

	public int compareTo(MovieInfo o) {
		/**
		 * // 先按照评分进行降序排序 int tmp = (int) (o.star - this.star); // 如果评分相等就按照年份进行排序 if
		 * (tmp == 0) { tmp = o.year-this.year; return tmp; } return tmp;
		 **/
		// 先按照评分进行降序排序
		if (o.star - this.star > 0) {
			return 1;
		} else if (o.star - this.star < 0) {
			return -1;
		}
		// 如果评分相等就按照年份进行排序
		if (o.year >= this.year) {
			return 1;
		} else {
			return -1;
		}
	}

	@Override
	public String toString() {
		return "电影[名称:" + title + ", 类型:" + type + ", 简介:" + actor + ", 评分:" + star + ", 年份:" + year + ", 封面图片:"
				+ film_page + "]";
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public float getStar() {
		return star;
	}

	public void setStar(float d) {
		this.star = d;
	}

	public String getDirector() {
		return director;
	}

	public void setDirector(String director) {
		this.director = director;
	}

	public String getActor() {
		return actor;
	}

	public void setActor(String actor) {
		this.actor = actor;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getFilm_page() {
		return film_page;
	}

	public void setFilm_page(String film_page) {
		this.film_page = film_page;
	}
}
